package lambda;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * @Author 12629
 * @Date 2022/4/4 20:52
 * @Description：
 */
class Test {
    public void test(){
        System.out.println("123");
    }
}

class Base {

    int a;
    public Base (int a) {
        this.a = a;
    }
}

class Derieve extends Base {

    public Derieve(int a) {
        super(a);
    }
}

public class Test2 {

    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");
        /*map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer integer, String s) {
                System.out.println("key: "+integer+" val:"+s);
            }
        });*/
        map.forEach((key,val)->System.out.println("key: "+key+" val:"+val));
    }

    public static void main2(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("bit");
        list.add("hello");
        list.add("Hello");
        list.add("lambda");

       /* list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("============");*/

        //流式表达式stream
        list.forEach(s-> System.out.println(s));

        /*list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });*/
        list.sort((o1,o2)->{return o1.compareTo(o2);});
        System.out.println("============");

        list.forEach(s-> System.out.println(s));
    }

    public static void main1(String[] args) {
        int a = 10;
        //a = 90;
        new Test() {
            @Override
            public void test() {
                System.out.println("hello"+ a);
            }
        }.test();

        System.out.println(a);
    }
}
